package com.siblings.loan.utils.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.siblings.loan.R
import com.siblings.loan.databinding.DialogTipsBinding
import com.siblings.loan.http.HttpHelper
import com.siblings.loan.utils.event.SibEventType

/**
 * Siblings
 * @Author wwdeng
 * @CreateTime: 2024/7/8 15:50
 * @Annotation：提示dialog
 */
class TipsDialog: ProDialog {

    private lateinit var binding: DialogTipsBinding
    private var mCallback: IDialogCallback? = null
    //事件备注
    private var eventRemark = ""

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context?, remark: String, callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = DialogTipsBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
    }

    override fun initListener() {
        setOnClickListener(R.id.ivClose) //关闭
        setOnClickListener(R.id.btnOk) //两个按钮 左侧按钮
        setOnClickListener(R.id.btnCancel) //两个按钮 又侧按钮
    }

    override fun initData() {
    }

    override fun onViewClick(v: View?) {
        dismiss()
        if(mCallback != null){
            mCallback!!.onClick(v)
        }
    }

    /**
     * 设置提示图标
     */
    fun setTipsIconResource(resId: Int){
        binding.ivIcon.setImageResource(resId)
    }

    /**
     * 设置提示title
     */
    fun setTipsTitle(title: String){
        binding.tvTipsTitle.text = title
    }

    /**
     * 设置提示语
     */
    fun setTips(tips: String){
        binding.tvTips.text = tips
    }

    /**
     * 显示取消按钮
     */
    fun showSibBtnCancel(){
        binding.btnCancel.visibility = View.VISIBLE
    }

    /**
     * 隐藏取消按钮
     */
    fun hideSibBtnCancel(){
        binding.btnCancel.visibility = View.GONE
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        HttpHelper.addSibEventAction(SibEventType.DIALOG.SIB_DIALOG_KIND_TIPS_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        HttpHelper.addSibEventAction(SibEventType.DIALOG.SIB_DIALOG_KIND_TIPS_DISMISS,eventRemark)
    }
}